import { request } from 'umi';
import {API} from './config';
import CustomRequest from '@/utils/Request'

/*
* 用户登录接口
* */
const login = async (loginInput, password) => {
  return await CustomRequest({
    api: API.login,
    method: 'get',
    params: { loginInput, password }
  })
}

/*
* 用户退出接口
* */
const loginOut = async () => {
  return request(API.logout, { 
    method: 'get' 
  })
}

/* 
* 获取用户信息
*/
const getUserInfo = async (params = {}) => {
  const res = await CustomRequest({
    api: API.loginUser,
    method: 'get',
    params: { ...params }
  });
  const {name, userId, role, unitId, unitType} = res;
  return {
    name: name,
    avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
    userid: userId,
    roleId: role ? role.roleId : '',
    unitId,
    unitType
  }
}

export default{
  login, // 登录
  loginOut,  // 退出
  getUserInfo
}
